<!--
  To change this template, choose Tools | Templates
  and open the template in the editor.
-->

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="rentadomus.Warehouse" %>  
<%@ page import="rentadomus.Office" %>  
<%@ page import="rentadomus.Local" %>  
<%@ page import="rentadomus.Apartament" %>  
<%@ page import="rentadomus.Dwelling" %>  
<%@ page import="rentadomus.House" %>  

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="layout" content="main">
    <title>Search Places</title>
    
  </head>
  <body>
    <script type="text/javascript">
      function paint(col)
      {
        document.bgColor=col;
      }
    </script>
    
    
      <g:form url="[controller:'searchByString', action:'index']">
       <g:textField name="string"/>
       <label for="SearchBy">
           Sort by: 
       </label>
       <g:select name="SearchBy" from="${['Price: Lowest first', 'Price: Highest first','Area: Lowest first', 'Area: Highest first']}" keys="${number}"/>
       <g:submitButton name="searchButton" value="Search" />
     </g:form>    
  
  <table>
    <thead>
      <tr>
          <td><h1>Image</h1></td>
          <td><h1>Title</h1></td>
          <td><h1>Price</h1></td>
          <td><h1>Area</h1></td>
        
      </tr>      
    </thead>
    <tbody>
      <g:each in="${list}" status="i" var="it">
        <tr>
          <td>
            <g:if test="${it.mainImage != 0}">
              <img class="normal" src="${createLink(controller:'UploadImage', action:'displayImage', id:(int)it.mainImage)}" />
            </g:if>
            <g:else>
              Image N/A
            </g:else>
          </td>
          <g:each in="${Warehouse.findAll()}" status="j" var="ot">
            <g:if test="${ot.idPlace.id == it.id}">
              <td>
                <a href="${createLink(controller:"Warehouse", action:'show', id:ot.id)}">${it.titlePlace}</a>
              </td>
            </g:if>              
          </g:each>
          <g:each in="${Office.findAll()}" status="j" var="ot">
            <g:if test="${ot.idPlace.id == it.id}">
              <td>
                <a href="${createLink(controller:"Office", action:'show', id:ot.id)}">${it.titlePlace}</a>
              </td>
            </g:if>
          </g:each>
          <g:each in="${Local.findAll()}" status="j" var="ot">
            <g:if test="${ot.idPlace.id == it.id}">
              <td>
                <a href="${createLink(controller:"Local", action:'show', id:ot.id)}">${it.titlePlace}</a>
              </td>
            </g:if>
          </g:each>
          
          <g:each in="${Dwelling.findAll()}" status="j" var="ot">          
            <g:if test="${ot.idPlace.id == it.id}">
              <g:each in="${Apartament.findAll()}" status="k" var="at">          
                <g:if test="${ot.id == at.idDwelling.id}">
                  <td>
                    <a href="${createLink(controller:"Apartament", action:'show', id:at.id)}">${it.titlePlace}</a>
                  </td>                  
                </g:if>
              </g:each>
              <g:each in="${House.findAll()}" status="k" var="at">          
                <g:if test="${ot.id == at.idDwelling.id}">
                  <td>
                    <a href="${createLink(controller:"House", action:'show', id:at.id)}">${it.titlePlace}</a>
                  </td>                  
                </g:if>
              </g:each>              
            </g:if>
          </g:each>
          <td>${it.rentPrice}</td>
          <td>${it.area}</td>
        </tr>
      </g:each>      
    </tbody>
  </table>
  <br><br><br><br>
       
       <a href="/RentADomus/" >
          <fieldset class="buttons">
                  <g:submitButton name="Back" class="back" value="Back" />
          </fieldset>

        </a>
      
    </body>
</html>
